package com.ctlele.team.space.fragment.impl;

import androidx.fragment.app.Fragment;

import com.ctlele.team.space.R;
import com.ctlele.team.space.adapter.AppPagerAdapter;
import com.ctlele.team.space.fragment.BaseFragment;
import com.ctlele.team.space.util.FileTypeUtils;
import com.ctlele.team.space.widget.view.FixedViewPager;
import com.flyco.tablayout.SlidingTabLayout;

import java.util.ArrayList;
import java.util.List;

public class HomeFragment extends BaseFragment {

    private static final String TAG = "HomeFragment";

    private ArrayList<Fragment> mFragmentList = new ArrayList<>();

    private List<String> mTitles = new ArrayList<>();

    private FixedViewPager mViewpager;

    private AppPagerAdapter mAdapter;

    private SlidingTabLayout mSlidingTabLayout;

    public HomeFragment() {
    }

    public static HomeFragment newInstance() {
        return new HomeFragment();
    }

    @Override
    protected int initLayout() {
        return R.layout.fragment_home;
    }

    @Override
    protected void initView() {
        mViewpager = mRootView.findViewById(R.id.fixed_view_pager);
        mSlidingTabLayout = mRootView.findViewById(R.id.sliding_tab_layout);

        mAdapter = new AppPagerAdapter(getFragmentManager(), new ArrayList<>(), new ArrayList<>());
        mViewpager.setAdapter(mAdapter);
    }

    @Override
    protected void initData() {
        FileTypeUtils.init(getContext());

        mTitles = new ArrayList<>();
        mFragmentList = new ArrayList<>();

        mTitles.add("我的网盘");
        mFragmentList.add(FileListFragment.createUserFileList());

        mTitles.add("团队空间");
        mFragmentList.add(FileListFragment.createGroupFileList());

        mTitles.add("我的好友");
        mFragmentList.add(FriendListFragment.createFriendList());

        mAdapter.flushData(mFragmentList, mTitles);
        mViewpager.setOffscreenPageLimit(0);
        mSlidingTabLayout.setViewPager(mViewpager);
    }
}